﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;
class Test
{
    string ques;
    string answ;
    bool correct;
    public Test (string q, string a,bool c)
    {
        ques = q;
        answ = a;
        correct = c;
    }
    
    public string arg()
    {
        return ques + " " + answ;
    }
    public string outt()
    {
        return answ;
    }
    public bool cor()
    {
        return correct;
    }

}
namespace tester
{
    class Program
    {
        static void Main(string[] args)
        {
            Process p = new Process();
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.FileName = "sortmytest.exe";
            List<Test> tests = new List<Test>();
            Test el = new Test(@"C:\testdir\test.txt", @"C:\testdir\testans.txt",true);
            tests.Add(el);
            el = new Test(@"C:\testdir\test00.txt", @"C:\testdir\test00ans.txt", true);
            tests.Add(el);
            el = new Test(@"C:\testdir\test1.txt", @"C:\testdir\test1ans.txt", true);
            tests.Add(el);
            el = new Test(@"C:\testdir\test0.txt", @"C:\testdir\test0ans.txt", true);
            tests.Add(el);
            el = new Test(@"C:\testdir\test3.txt", @"C:\testdir\test3ans.txt", false);
            tests.Add(el);
            el = new Test(@"C:\testdir\test4.txt", @"C:\testdir\test4ans.txt", true);
            tests.Add(el);
            el = new Test(@"C:\testdir\test5.txt", @"C:\testdir\test5ans.txt", true);
            tests.Add(el);
            el = new Test(@"C:\testdir\test9999.txt", @"C:\testdir\test5ans.txt", true);
            tests.Add(el);
            foreach (Test ell in tests)
            {
                p.StartInfo.Arguments = ell.arg();
                p.Start();
                p.WaitForExit();
                if (!ell.cor())
                {
                    break;
                }
                StreamReader input = new StreamReader(ell.outt());
                int tek = 0; 
                int prev = 0;
                int error = 0;
                int y = 0;
                int h = 0;
                while (!input.EndOfStream)
                {                    
                    prev = tek;
                    tek = 0;
                    while ((input.Peek() == ' ') && (!input.EndOfStream))
                    {
                        y++;
                        input.Read();
                    }
                    if (input.EndOfStream)
                    {
                        tek = -1;
                        break;
                    }
                    
                    while ((!input.EndOfStream)&&(input.Peek() != ' '))
                    {
                        tek *= 10;
                        y++;
                        h = (int)(input.Read() - '0');
                        if (h == -48)
                        {
                            tek = -1;
                            break;
                        }
                        tek += h;
                    }
                    input.Read();
                    y++;
                    if (tek == -1)
                    { 
                        break; 
                    }
                    if (tek < prev)
                    {
                        Console.WriteLine("WRONG  test" + ell.arg());
                        error = tek;
                        tek = -1;
                        break;
                    }
                }
                if ((tek < prev)&&(tek!=-1))
                {
                    Console.WriteLine("WRONG  test" + ell.arg());
                }
                input.Close();
            }
        }
    }
}
